import Vue from "vue";
import "../../style/basic.less";
import "./info.less";
import pageing from "../../components/pageing/pageing.js";
import {request} from "../../util/request.js";
new Vue({
    el:"#louie",
    data:{
        total:{},  //数据
        today:{},  //今日统计
        returnNum:20,  //请求数据数量
        pageNum:1,  //当前page页面
        data_total:0,
        list:[]   //列表
    },
    components:{
        page:pageing
    },
    created:function(){
        this.getTotalTodayData();
        this.getTotal()
            .then(()=>{
                if(this.data_total > 0){
                    this.getList();
                }
            });
    },
    methods:{
        /**
         * 获取历史总数据
         */
        getTotalTodayData:function(){
            request('info/getTotalTodayData')
                .then((res)=>{
                    if(res.data.status == "success"){
                        let data = res.data.data;
                        this.total = data.total;
                        this.today = data.today;
                    }
                });
        },
        /**
         * 获取列表数据总数
         */
        getTotal(){
            return new Promise((success)=>{
                request('info/getTotal')
                    .then((res)=>{
                        if(res.data.status === "success"){
                            this.data_total = res.data.data;
                            success();
                        }
                    });
            });
        },
        /**
         * 获取列表
         */
        getList(){
            request("info/getList",{
                limit:[(this.pageNum-1)*this.returnNum,this.returnNum]
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        this.list = res.data.data;
                    }
                });
        },
        /**
         * 点击分页
         * @param page
         */
        changePage:function(page){
            this.pageNum = page;
            this.getList();
        }
    }
});